;【AHK2】                                                                                
; http://cenalulu.github.io/images/linux/vim_cheatsheet/classic.gif                    
; http://ahkv2.mallocx.com/Tutorial.htm                                                
; https://www.autohotkey.com/boards/viewforum.php?f=82&start=25                        
; Hotkey Resource: https://www.autohotkey.com/docs/v1/Hotkeys.htm#Symbols              
; Symbol Legend - [#, ^, !, +] are modifiers                                           
; # = Windows Key                                                                      
; ^ = Ctrl                                                                             
; ! = Alt                                                                              
; + = Shift                                                                            
                                                                                       
                                                                                       
;系统快捷键                                                                                 
;=====================================================================o                
;                    CapsLock Direction Navigator                                      
;-----------------------------------o---------------------------------o                
;      键\修饰    	✱	     !(+)	      ^         ^!                                     
;        h         ←         选字        跳词      跳选词                                     
;        j         ↓         选字        跳词      跳选词                                     
;        k         ↑         选字        跳词      跳选词                                     
;        l         →         选字        跳词      跳选词                                     
;        u        PgUp       选字        跳词      跳选词                                     
;        p        PgDn       选字        跳词      跳选词                                     
;        ,        Home       选字        跳词      跳选词                                     
;        .        End        选字        跳词      跳选词                                     
;-----------------------------------o---------------------------------o                
sys_hotkey(key1, key2){                                                                
  hot(key1){                                                                           
    Switch{                                                                            
        case (GetKeyState("control") = 0 and GetKeyState("Alt") = 0): Send      key2   
        case (GetKeyState("control") = 0 and GetKeyState("Alt") = 1): Send "^"  key2   
        case (GetKeyState("control") = 1 and GetKeyState("Alt") = 0): Send "+"  key2   
        case (GetKeyState("control") = 1 and GetKeyState("Alt") = 1): Send "+^" key2   
        }                                                                              
  }                                                                                    
                                                                                       
  hotkey key1, hot                                                                     
}                                                                                      
sys_hotkey("CapsLock & h", "{left}")                                                   
sys_hotkey("CapsLock & j", "{down}")                                                   
sys_hotkey("CapsLock & k", "{up}")                                                     
sys_hotkey("CapsLock & l", "{right}")                                                  
sys_hotkey("CapsLock & -", "{PgUp}")                                                   
sys_hotkey("CapsLock & =", "{PgDn}")                                                   
sys_hotkey("CapsLock & ,", "{Home}")                                                   
sys_hotkey("CapsLock & .", "{End}")                                                    
                                                                                       
CapsLock & backspace::{                                                                
static count:=0                                                                        
if count>0{                                                                            
    count++                                                                            
    return                                                                             
}                                                                                      
count:=1                                                                               
settimer after, -300                                                                   
after(){                                                                               
    if count=1{                                                                        
        send "{del}"                                                                   
    }                                                                                  
    else if count=2{                                                                   
         send "^{del}"                                                                 
    }                                                                                  
    else if count=3{                                                                   
         send "{home}+{end}{del}"                                                      
    }                                                                                  
    else if count>3{                                                                   
        tooltip count                                                                  
    }                                                                                  
    count:=0                                                                           
}                                                                                      
}                                                                                      
                                                                                       
CapsLock & s::                                                                         
{                                                                                      
    if GetKeyState("Ctrl") or GetKeyState("Alt") = 1                                   
        Send "^+{Tab}"                                                                 
    else                                                                               
        Send "^{Tab}"                                                                  
}                                                                                      
                                                                                       
CapsLock & q::                                                                         
{                                                                                      
    if GetKeyState("Alt") = 0                                                          
        Send "^{F4}"                                                                   
    else                                                                               
        Send "!{F4}"                                                                   
}                                                                                      
                                                                                       
; close Tab                                                                            
CapsLock & w:: {                                                                       
    Send "{Blind}^w"                                                                   
}                                                                                      
                                                                                       
Capslock & p:: {
    run "Start-Process powershell -Verb runAs"
}                                                                                       
                                                                                       
;置顶当前窗口                                                                                
CapsLock & t::                                                                         
{                                                                                      
	WinSetAlwaysOnTop -1, "A"                                                          
	ToolTip "Caps+t to stick the window or cancel it."                                 
}                                                                                      
                                                                                       
ToolTip "CapsLock toolkit starts in 5s."                                               
SetTimer () => ToolTip(), -5000                                                        
                                                                                       
                                                                                       
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  
; Obsidian 快捷键                                                                         
#HotIf winactive("ahk_exe Obsidian.exe")                                               
^!c::MsgBox "You pressed Control+Alt+C in Notepad."                                    
^5:: send  "{end}~~{home}~~{end}" ;删除线                                                 
^6:: send "{home}{del}{del}{end}{backspace}{backspace}" ;取消删除线                         
#HotIf                                                                                 
                                                                                       
;判断是否使用notepad2程序                                                                      
#n::                                                                                   
{                                                                                      
    if WinExist("ahk_class Notepad2")                                                  
        WinActivate  ; Activate the window found above                                 
    else                                                                               
        Run "notepad"  ; Open a new Notepad window                                     
}                                                                                      
                                                                                       
                                                                                       
                                                                                       
;sys_hotkey参考此例做成                                                                      
app_hotkey(keyname, app_title, app_path)                                               
{                                                                                      
    activate(keyname)  ; This will be a closure due to app_title and app_path.         
    {                                                                                  
        if WinExist(app_title)                                                         
            WinActivate                                                                
        else                                                                           
            Run app_path                                                               
    }                                                                                  
    Hotkey keyname, activate                                                           
}                                                                                      
; Win+N activates or launches Notepad.                                                 
app_hotkey "#n", "ahk_class Notepad", "notepad.exe"                                    
; Win+W activates or launches WordPad.                                                 
app_hotkey "#w", "ahk_class WordPadClass", "wordpad.exe"                               
                                                                                       
                                                                                       
Hotkey "^!z", MyFunc                                                                   
MyFunc(ThisHotkey)                                                                     
{                                                                                      
    MsgBox "You pressed " ThisHotkey                                                   
}                                                                                      
a := "abc"                                                                             
b := 100                                                                               
c := "def"                                                                             
d := 123.456                                                                           
e := 200                                                                               
                                                                                       
; f 的值是字符串 abc100anddef123.456                                                         
f := a b "and" c d                                                                     
; g 的值是字符串 100200                                                                      
g := b e                                                                               